﻿using NCD.Utility.Entity;
using OldDataSync.NewDomains;
using SqlSugar;
namespace OldDataSync
{
    /// <summary>
    /// 数据库上下文
    /// </summary>
    public class DBContext
    {
        public DBContext(string connection)
        {
            OldDb = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = connection.Replace("table", "NCD_Database"),
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.SystemTable
            });

            NewDb = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = connection.Replace("table", "SXICE"),
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute
            });
        }

        /// <summary>
        /// 用来处理事务多表查询和复杂的操作
        /// </summary>
        public SqlSugarClient OldDb;

        public SqlSugarClient NewDb;

        /*
         * 新数据对象
         */
        /// <summary>
        /// 客户数据操作对象
        /// </summary>
        public SimpleClient<Customer> CustomerDB => new SimpleClient<Customer>(NewDb);
        /// <summary>
        /// 心脑血管选项数据操作对象
        /// </summary>
        public SimpleClient<VASelections> VASelectionsDB => new SimpleClient<VASelections>(NewDb);
        /// <summary>
        /// 心脑血管记录数据操作对象
        /// </summary>
        public SimpleClient<VARecords> VARecordsDB => new SimpleClient<VARecords>(NewDb);
        /// <summary>
        /// 体检值
        /// </summary>
        public SimpleClient<LTHRValues> LTHRValuesDB => new SimpleClient<LTHRValues>(NewDb);
        /// <summary>
        /// 心理记录数据操作对象
        /// </summary>
        public SimpleClient<PARecords> PARecordsDB => new SimpleClient<PARecords>(NewDb);
        /// <summary>
        /// 心理选项数据操作对象
        /// </summary>
        public SimpleClient<PASelections> PASelectionsDB => new SimpleClient<PASelections>(NewDb);
        /// <summary>
        /// 心理问题数据操作对象
        /// </summary>
        public SimpleClient<PAQuestion> PAQuestionDB => new SimpleClient<PAQuestion>(NewDb);
        /// <summary>
        /// 心理答案数据操作对象
        /// </summary>
        public SimpleClient<PAAnswer> PAAnswerDB => new SimpleClient<PAAnswer>(NewDb);
        /// <summary>
        /// 心理问题数据操作对象
        /// </summary>
        public SimpleClient<VAQuestion> VAQuestionDB => new SimpleClient<VAQuestion>(NewDb);
        /// <summary>
        /// 心理答案数据操作对象
        /// </summary>
        public SimpleClient<VAAnswer> VAAnswerDB => new SimpleClient<VAAnswer>(NewDb);
        /// <summary>
        /// 心理答案数据操作对象
        /// </summary>
        public SimpleClient<LTHR> LTHRDB => new SimpleClient<LTHR>(NewDb);



        /*
         * 旧数据对象
         */
        /// <summary>
        /// 客户数据操作对象
        /// </summary>
        public SimpleClient<BaseUserInformation> OldCustomerDB => new SimpleClient<BaseUserInformation>(OldDb);
        /// <summary>
        /// 心脑血管选项数据操作对象
        /// </summary>
        public SimpleClient<BaseSelections> OldSelectionsDB => new SimpleClient<BaseSelections>(OldDb);
        /// <summary>
        /// 心脑血管记录数据操作对象
        /// </summary>
        public SimpleClient<NCD_VAScores> OldVARecordsDB => new SimpleClient<NCD_VAScores>(OldDb);
        /// <summary>
        /// 体检值
        /// </summary>
        public SimpleClient<NCD_LTHRValues> OldLTHRValuesDB => new SimpleClient<NCD_LTHRValues>(OldDb);
        /// <summary>
        /// 心理记录数据操作对象
        /// </summary>
        public SimpleClient<NCD_PsychologyScores> OldPARecordsDB => new SimpleClient<NCD_PsychologyScores>(OldDb);
    }
}